import math
num,k = list(map(int, input().split(' ')))
count = 0
for i in (range(num)):
rang = list(map(int, input().split(' ')))
count += rang[1]-rang[0]+1
count = k* math.ceil(count/k) - count
print(count)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<cmath> //float result = pow(b,p) //trunc(10.25)=10 // floor(10.55)=10 // ceil(10.55)=11 //round(10.1)=10 , round(10.55)=11
#include <unordered_map> // unordered_map<int,int>mp;
using namespace std;
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// -842150451
// a=97 , z= 122 , A=65 ,Z=90
#include<set>
int main() {
//extern int arr [5] ;
//fast
int before=0 , after =0 ;
int n, k; cin >> n >> k;
for (int i = 0;i<n;i++) {
int l; cin >> l;
int r; cin >> r;
before += 1 + r - l;
}
for (int i = 0; true; i++) {
if ((after+before) % k == 0) {
break;
}
after++;
}
cout << after << endl;
}
41C - Email address | 1373D - Maximum Sum on Even Positions |
1574C - Slay the Dragon | 621A - Wet Shark and Odd and Even |
1395A - Boboniu Likes to Color Balls | 1637C - Andrew and Stones |
1334B - Middle Class | 260C - Balls and Boxes |
1554A - Cherry | 11B - Jumping Jack |
716A - Crazy Computer | 644A - Parliament of Berland |
1657C - Bracket Sequence Deletion | 1657B - XY Sequence |
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |
1321A - Contest for Robots | 1451A - Subtract or Divide |
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |